/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef DRAWING_BENCH_TEST_CASE_BEIZER_H
#define DRAWING_BENCH_TEST_CASE_BEIZER_H
#include "drawing_bench_test_base.h"

namespace OHOS {
namespace Rosen {

struct BezierRec {
    Drawing::Canvas*   fCanvas;
    Drawing::Pen       fPaint;
    Drawing::Path      fQuad;
    Drawing::Path      fCubic;
};

typedef const char* (*DrawProc)(const BezierRec*, int);

static const char* draw_quad(const BezierRec* rec, int count) {
    if (rec) {
        Drawing::Canvas* canvas = rec->fCanvas;
        canvas->AttachPen(rec->fPaint);
        const Drawing::Path& path = rec->fQuad;
        for (int i = 0; i < count; ++i) {
            canvas->DrawPath(path);
        }
    }
    return "quad";
}

static const char* draw_cubic(const BezierRec* rec, int count) {
    if (rec) {
        Drawing::Canvas* canvas = rec->fCanvas;
        canvas->AttachPen(rec->fPaint);
        const Drawing::Path& path = rec->fCubic;
        for (int i = 0; i < count; ++i) {
            canvas->DrawPath(path);
        }
    }
    return "cubic";
}

class DrawBenchBeizer : public TestBase {
    Drawing::Pen       fPaint;
    Drawing::Path      fQuad;
    Drawing::Path      fCubic;    
    Drawing::scalar fWidth;
    Drawing::Color cl;
    BezierRec fRec;
    DrawProc fProc;
public:
    DrawBenchBeizer() : TestBase() {
        fProc = draw_quad;
        fWidth = 2.0f;
        cl = 0xFF00FF00;
        fRec.fQuad.MoveTo(20, 20);
        fRec.fQuad.QuadTo(60, 20, 60, 60);
        fRec.fQuad.QuadTo(20, 60, 20, 100);
        fRec.fCubic.MoveTo(20, 20);
        fRec.fCubic.CubicTo(40, 20, 60, 40, 60, 60);
        fRec.fCubic.CubicTo(40, 60, 20, 80, 20, 100);        
    }
    virtual ~DrawBenchBeizer() = default;

protected:

    void OnTestPerformance(Drawing::Canvas* canvas) override
    {
        std::cout<<"OnTestPerformance start"<<std::endl;
        fRec.fCanvas = canvas;
        // fRec.fPaint.SetStyle(SkPaint::kStroke_Style);
        fRec.fPaint.SetCapStyle(Drawing::Pen::CapStyle::FLAT_CAP);
        fRec.fPaint.SetJoinStyle(Drawing::Pen::JoinStyle::BEVEL_JOIN);
        fRec.fPaint.SetWidth(fWidth);
        fRec.fPaint.SetColor(cl);
        fProc(&fRec, testCount_);
        std::cout<<"OnTestPerformance case 1 finish"<<std::endl;
        sleep(5);
        fProc = draw_cubic;
        fRec.fPaint.SetCapStyle(Drawing::Pen::CapStyle::FLAT_CAP);
        fRec.fPaint.SetJoinStyle(Drawing::Pen::JoinStyle::ROUND_JOIN);        
        fProc(&fRec, testCount_);
        std::cout<<"OnTestPerformance case 2 finish"<<std::endl;
    }

};

} // namespace Rosen
} // namespace OHOS
#endif // DRAWING_BENCH_TEST_CASE_BEIZER_H